package org.zjt.servlet3;


import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Arrays;

/**
 * DESC
 *
 * @author
 * @create 2017-07-17 下午4:39
 **/

//@WebFilter(servletNames = {"myServlet"})
@WebFilter(urlPatterns = {"/myServlet"})
public class MyFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        httpServletRequest.getParameterMap().forEach((k, v) -> httpServletRequest.getServletContext().log("拦截器:"+k + "  " + String.valueOf(Arrays.stream(v).reduce(new String(), (a, b) -> b + "," + a, (a, b) -> b + a))));
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    }
}
